Because the host adapter driver may allocate virtual memory, it may sleep. Some host adapter drivers allocate all the resources they need on the first call to scsi_alloc() and do little or nothing on subsequent calls. However, you cannot predict whether your driver will make the first call or not.
A SCSI device driver will typically call the scsi_alloc() function from the pfxopen() entry point. However, if the driver needs to issue commands to the device at initialization time, it would call scsi_alloc(), use scsi_command(), and call scsi_free(), all within the pfxinit() or pfxedtinit() entry point.
A call to scsi_alloc() specifies these parameters:
adap, targ, lun | Numbers that identify the device on the bus. |
option | An integer comprising two parameters, a flag and a count. |
callback | Address of a function to be called whenever sense data is gotten from the device. |
The option parameter may include the SCSIALLOC_EXCLUSIVE flag to request exclusive use of the target. For example, a tape device driver would typically use exclusive access, while a disk device driver would not. If another driver has allocated a path to the same device, scsi_alloc() return EBUSY.
The option parameter may include SCSIALLOC_NOSYNC to specify that this device should not, or cannot, use synchronous transfer mode. That setting can be overridden for single commands by a flag to scsi_command() (see Table 15-4).
The option parameter can also include a small integer value indicating the number of SCSI commands the driver would like to start before any have completed. The call to scsi_info() returns the maximum number of commands that can be queued in this way; a larger number is ignored.
The callback function address can be specified as NULL. The specified callback function is called only when sense data is gotten from the allocated device. Only one driver that allocates a path to a device can specify a callback function. If the path is not held exclusively, any other drivers must specify a null address for their callback functions.